import lodash from "lodash"
export default {
  data() {
      return {
      //表格最大高度
      tableMaxHeight: 0,
      //不必要的高度
      unNecessaryHeight:200,
      //表格头部高度
      tableHeadHeight:0
      };
  },
  activated () {
    window.onresize = () => {
      return (() => {
        this.setTableMaxHeight(document.body.clientHeight)
      })()
    }
  },
  mounted () {
    this.$nextTick(() => {
      this.computerBottom()
      this.tableMaxHeight = document.body.clientHeight - this.unNecessaryHeight
    })
    window.onresize = () => {
      return (() => {
        this.setTableMaxHeight(document.body.clientHeight)
      })()
    }
  },
  methods:{
    setTableMaxHeight: lodash.debounce(function(currentHeight){
      if(currentHeight > this.unNecessaryHeight){
        const  mh = currentHeight - this.unNecessaryHeight
        this.tableMaxHeight = mh < this.tableHeadHeight ? this.tableHeadHeight : mh
      }
    },40),
    computerBottom () {
      const table = (this.$refs.dynamicHeightTable || this.$refs.tables)?.$el

      this.tableHeadHeight = table.querySelector('.el-table__header-wrapper').offsetHeight
      this.tableHeadHeight = this.tableHeadHeight+80 || 0

      let node = table
      let tmp = 0
      while (node != null) {
        tmp += node.offsetTop;
        node = node.offsetParent;
      }
      this.unNecessaryHeight = tmp
    }
  }
};